// LPP.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"




using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	
 

	switch(2){
	case 1:{
		Lexico *lexico = new Lexico("test.lpp");
	Token *token = new Token();
	ofstream myfile;
	myfile.open ("tokens.txt");
	int i=0;
 try{
	 do{
		token = lexico->getNextToken();
		i++;
		/*myfile << "Nombre: ";
		TokenType ty;
		myfile << ty.returntokenstring(token->getCod());
		myfile << " Cod: ";
		myfile << token->getCod();
		myfile << " Lexema: ";
		myfile << token->getLexema();
		myfile << " linea: ";
		myfile << token->getLinea();
		myfile << " columna: ";
		myfile << token->getColumna()<<endl;*/

	 }while(token->getCod() != 69);
	 

 }catch(exception e){
	 cout<<e.what()<<endl;
 }


	myfile.close();
	cout<<i<<endl;
	break;
		   }

	case 2:{
		cout<<"Compilando...."<<endl;
		try{
			
	Sintactico *sintatico = new Sintactico("testA.lpp");
	Sentencia* sentencia = sintatico->S();
	if(sentencia!=0){
	sentencia->validarSemantica(sintatico->getTablaTipos(),sintatico->getTablaVaribales());
	}
	//Print *print = new Print(sentencia);
	
	}catch(exception e){
	 cout<<e.what()<<endl;
 }
		break;
		   }


	case 3:{
		ifstream file;
		file.open("Proyecto1_20911176.lpp", ios::binary);
		if(file.is_open()){
			cout<<"begin";
			while(file.good()){
			file.get();
			//cout<<file.get()<<endl;
			}
			cout<<"end";
		}
		break;
		   }

	case 4:{
			 int length;
  char * buffer;
		ifstream file;
		file.open("Proyecto1_20911176.lpp", ios::binary);
		 // get length of file:
  file.seekg (0, ios::end);
  length = file.tellg();
  file.seekg (0, ios::beg);

  // allocate memory:
  buffer = new char [length];

  // read data as a block:
  file.read (buffer,length);
  file.close();

  //cout.write (buffer,length);

  delete[] buffer;
		break;
		   }
	}
	
	system("pause");
	return 0;
}
